#include<iostream>
using namespace std;

long long solve(long long int m,long long int k)
{
	long long s;
	if(k==1)
	{
		return m;
	}
	s=solve(m,k/2)%10;



	if(k%2==0)
	return (s*s%10);
	
	else
	{return (s*s*m%10);}
}

int main()
{
	int  t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		
	cout<<solve(n,n)<<endl;
		
	}
	return 0;
} 
